﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class KZForm : Form
    {
        int roomId;
        public KZForm()
        {
            InitializeComponent();
        }

        private void KZForm_Load(object sender, EventArgs e)
        {
            if (!RuningData.FormDir.ContainsKey(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name))
            {
                RuningData.FormDir.Add(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, this);
            }

            roomId = Convert.ToInt32(RuningData.CurrRoomNmae.Split('-')[1]);
            RoomModel currRoom =  RuningData.GetRoom(roomId);
            textBox1.Text = currRoom.RoomJC;
            textBox2.Text = currRoom.GuestName;
            //dateTimePicker1.Value
            textBox3.Text = currRoom.Num.ToString();
            RuningData.WaitersInit();
            foreach(WaiterModel item in RuningData.Waiters)
            {
                comboBox1.Items.Add(item.WaiterName);
            }
            comboBox1.SelectedIndex = 0;
            textBox5.Text = currRoom.RoomBZ;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RoomModel newRoom = RuningData.GetRoom(roomId);
            newRoom.RoomJC = textBox1.Text;
            newRoom.GuestName = textBox2.Text;
            newRoom.Num = Convert.ToInt32(textBox3.Text);
            newRoom.ZhangDan = dateTimePicker1.Value.ToString();
            newRoom.WaiterName = comboBox1.Text;
            newRoom.RoomBZ = textBox5.Text;
            newRoom.RoomZT = "使用";
            RuningData.UpdateRoom(newRoom);
            MessageBox.Show("桌台信息更新成功!");
            this.Hide();
            RuningData.FormDir["Form2"].Show();
        }
    }
}
